
****INDIVIDUAL FORECASTS 
eststo clear

use "$jfqa_rep/21_DJIA_convexity_60.dta", clear

qui{
merge 1:m year month day using "$jfqa_rep/Shiller_Individual_Ests.dta"
keep if _merge==3
drop _merge

sort year month day

gen monthyear=ym(year, month)

drop if abs(dow_1m)>=.5

gen wret_1=(1+ret_5)*(1+ret_1)*(1+ret_2)*(1+ret_3)*(1+ret_4)-1
gen wret_2=(1+ret_10)*(1+ret_6)*(1+ret_7)*(1+ret_8)*(1+ret_9)-1
gen wret_3=(1+ret_15)*(1+ret_11)*(1+ret_12)*(1+ret_13)*(1+ret_14)-1
gen wret_4=(1+ret_20)*(1+ret_16)*(1+ret_17)*(1+ret_18)*(1+ret_19)-1
gen wret_5=(1+ret_25)*(1+ret_21)*(1+ret_22)*(1+ret_23)*(1+ret_24)-1
gen wret_6=(1+ret_30)*(1+ret_26)*(1+ret_27)*(1+ret_28)*(1+ret_29)-1
gen wret_7=(1+ret_35)*(1+ret_31)*(1+ret_32)*(1+ret_33)*(1+ret_34)-1
gen wret_8=(1+ret_40)*(1+ret_36)*(1+ret_37)*(1+ret_38)*(1+ret_39)-1
gen wret_9=(1+ret_45)*(1+ret_41)*(1+ret_42)*(1+ret_43)*(1+ret_44)-1
gen wret_10=(1+ret_50)*(1+ret_46)*(1+ret_47)*(1+ret_48)*(1+ret_49)-1
gen wret_11=(1+ret_55)*(1+ret_51)*(1+ret_52)*(1+ret_53)*(1+ret_54)-1
gen wret_12=(1+ret_60)*(1+ret_56)*(1+ret_57)*(1+ret_58)*(1+ret_59)-1

gen futwret_1=(1+futret_1)*(1+futret_2)*(1+futret_3)*(1+futret_4)*(1+futret_5)-1
gen futwret_2=(1+futret_6)*(1+futret_7)*(1+futret_8)*(1+futret_9)*(1+futret_10)-1
gen futwret_3=(1+futret_11)*(1+futret_12)*(1+futret_13)*(1+futret_14)*(1+futret_15)-1
gen futwret_4=(1+futret_16)*(1+futret_17)*(1+futret_18)*(1+futret_19)*(1+futret_20)-1
gen futmret_1=(1+futwret_1)*(1+futwret_2)*(1+futwret_3)*(1+futwret_4)*(1+futret_21)-1

collapse lag_convexity wret* dow_1m fut*, by(year month day monthyear)

gen obs=_n

gen fit_expect_12=.
tsset obs

*12 lags
forval i=500/2538 {	
nl (dow_1m = {b0} + ///
	{b1}*(({b2}*wret_1)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^2*wret_2)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^3*wret_3)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^4*wret_4)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^5*wret_5)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^6*wret_6)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^7*wret_7)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^8*wret_8)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^9*wret_9)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^10*wret_10)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^11*wret_11)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^12*wret_12)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12)))  ///
		if obs<(`i'+1), initial(b0 0 b1 1 b2 0.5) nolog vce(cluster monthyear)

gen fit_expect =_b[/b0] + ///
	_b[/b1]*((_b[/b2]*wret_1)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12) + ///
		(_b[/b2]^2*wret_2)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12) + ///
		(_b[/b2]^3*wret_3)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12) + ///
		(_b[/b2]^4*wret_4)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12) + ///
		(_b[/b2]^5*wret_5)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b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[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12))   if obs<(`i'+1)
	
replace fit_expect_12=fit_expect if obs==`i'
drop fit_expect
}

drop if missing(fit_expect_12)

replace fit_expect_12=fit_expect_12*100
replace futmret_1=futmret_1*100
replace dow_1m=dow_1m*100

gen res_expect_12=dow_1m-fit_expect_12
egen res_expect_12_std=std(res_expect_12)
egen fit_expect_12_std=std(fit_expect_12)
egen dow_1m_std=std(dow_1m)
egen convex_std=std(lag_convexity)
}

****TABLE 10****
*coefficients and t-stats
newey futmret_1 dow_1m_std, lag(8)
newey futmret_1 fit_expect_12_std, lag(8)
newey futmret_1 res_expect_12_std, lag(8)

*R-squared
reg futmret_1 dow_1m_std
reg futmret_1 fit_expect_12_std
reg futmret_1 res_expect_12_std

****TABLE 11****
*coefficients and t-stats
newey dow_1m convex_std, lag(8)
newey fit_expect_12 convex_std, lag(8)
newey res_expect_12 convex_std, lag(8)

*R-squared
reg dow_1m convex_std
reg fit_expect_12 convex_std
reg res_expect_12 convex_std

****INSTITUTIONAL FORECASTS
use "$jfqa_rep/21_DJIA_convexity_60.dta", clear

qui{
merge 1:m year month day using "$jfqa_rep/Shiller_Inst_Ests.dta"
keep if _merge==3
drop _merge

sort year month day

gen monthyear=ym(year, month)

drop if year<1993

drop if abs(dow_1m)>=.5

gen wret_1=(1+ret_5)*(1+ret_1)*(1+ret_2)*(1+ret_3)*(1+ret_4)-1
gen wret_2=(1+ret_10)*(1+ret_6)*(1+ret_7)*(1+ret_8)*(1+ret_9)-1
gen wret_3=(1+ret_15)*(1+ret_11)*(1+ret_12)*(1+ret_13)*(1+ret_14)-1
gen wret_4=(1+ret_20)*(1+ret_16)*(1+ret_17)*(1+ret_18)*(1+ret_19)-1
gen wret_5=(1+ret_25)*(1+ret_21)*(1+ret_22)*(1+ret_23)*(1+ret_24)-1
gen wret_6=(1+ret_30)*(1+ret_26)*(1+ret_27)*(1+ret_28)*(1+ret_29)-1
gen wret_7=(1+ret_35)*(1+ret_31)*(1+ret_32)*(1+ret_33)*(1+ret_34)-1
gen wret_8=(1+ret_40)*(1+ret_36)*(1+ret_37)*(1+ret_38)*(1+ret_39)-1
gen wret_9=(1+ret_45)*(1+ret_41)*(1+ret_42)*(1+ret_43)*(1+ret_44)-1
gen wret_10=(1+ret_50)*(1+ret_46)*(1+ret_47)*(1+ret_48)*(1+ret_49)-1
gen wret_11=(1+ret_55)*(1+ret_51)*(1+ret_52)*(1+ret_53)*(1+ret_54)-1
gen wret_12=(1+ret_60)*(1+ret_56)*(1+ret_57)*(1+ret_58)*(1+ret_59)-1

gen futwret_1=(1+futret_1)*(1+futret_2)*(1+futret_3)*(1+futret_4)*(1+futret_5)-1
gen futwret_2=(1+futret_6)*(1+futret_7)*(1+futret_8)*(1+futret_9)*(1+futret_10)-1
gen futwret_3=(1+futret_11)*(1+futret_12)*(1+futret_13)*(1+futret_14)*(1+futret_15)-1
gen futwret_4=(1+futret_16)*(1+futret_17)*(1+futret_18)*(1+futret_19)*(1+futret_20)-1
gen futmret_1=(1+futwret_1)*(1+futwret_2)*(1+futwret_3)*(1+futwret_4)*(1+futret_21)-1

collapse lag_convexity wret* dow_1m fut*, by(year month day monthyear)

gen obs=_n

gen fit_expect_12=.
tsset obs

*12 lags
forval i=500/2529 {	
nl (dow_1m = {b0} + ///
	{b1}*(({b2}*wret_1)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^2*wret_2)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^3*wret_3)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^4*wret_4)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^5*wret_5)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^6*wret_6)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^7*wret_7)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^8*wret_8)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^9*wret_9)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^10*wret_10)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^11*wret_11)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^12*wret_12)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12)))  ///
		if obs<(`i'+1), initial(b0 0 b1 1 b2 0.5) nolog vce(cluster monthyear)

gen fit_expect =_b[/b0] + ///
	_b[/b1]*((_b[/b2]*wret_1)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^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2]^12) + ///
		(_b[/b2]^9*wret_9)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12) + ///
		(_b[/b2]^10*wret_10)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12) + ///
		(_b[/b2]^11*wret_11)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12) + ///
		(_b[/b2]^12*wret_12)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12))   if obs<(`i'+1)
	
replace fit_expect_12=fit_expect if obs==`i'
drop fit_expect
}

drop if missing(fit_expect_12)

replace fit_expect_12=fit_expect_12*100
replace futmret_1=futmret_1*100
replace dow_1m=dow_1m*100

gen res_expect_12=dow_1m-fit_expect_12
egen res_expect_12_std=std(res_expect_12)
egen fit_expect_12_std=std(fit_expect_12)
egen dow_1m_std=std(dow_1m)
egen convex_std=std(lag_convexity)
}

****TABLE 10****
*coefficients and t-stats
newey futmret_1 dow_1m_std, lag(8)
newey futmret_1 fit_expect_12_std, lag(8)
newey futmret_1 res_expect_12_std, lag(8)

*R-squared
reg futmret_1 dow_1m_std
reg futmret_1 fit_expect_12_std
reg futmret_1 res_expect_12_std

****TABLE 11****
*coefficients and t-stats
newey dow_1m convex_std, lag(8)
newey fit_expect_12 convex_std, lag(8)
newey res_expect_12 convex_std, lag(8)

*R-squared
reg dow_1m convex_std
reg fit_expect_12 convex_std
reg res_expect_12 convex_std

****ALL FORECASTS 
eststo clear
use "$jfqa_rep/21_DJIA_convexity_60.dta", clear

qui{
merge 1:m year month day using "$jfqa_rep/Shiller_Inst_Ests.dta"
keep if _merge==3
drop _merge

preserve
tempfile copy

use "$jfqa_rep/21_DJIA_convexity_60.dta", clear

merge 1:m year month day using "$jfqa_rep/Shiller_Individual_Ests.dta"
keep if _merge==3
drop _merge

save `copy', replace

restore
append using `copy'

sort year month day

gen monthyear=ym(year, month)

drop if year<1993

drop if abs(dow_1m)>=.5

gen wret_1=(1+ret_5)*(1+ret_1)*(1+ret_2)*(1+ret_3)*(1+ret_4)-1
gen wret_2=(1+ret_10)*(1+ret_6)*(1+ret_7)*(1+ret_8)*(1+ret_9)-1
gen wret_3=(1+ret_15)*(1+ret_11)*(1+ret_12)*(1+ret_13)*(1+ret_14)-1
gen wret_4=(1+ret_20)*(1+ret_16)*(1+ret_17)*(1+ret_18)*(1+ret_19)-1
gen wret_5=(1+ret_25)*(1+ret_21)*(1+ret_22)*(1+ret_23)*(1+ret_24)-1
gen wret_6=(1+ret_30)*(1+ret_26)*(1+ret_27)*(1+ret_28)*(1+ret_29)-1
gen wret_7=(1+ret_35)*(1+ret_31)*(1+ret_32)*(1+ret_33)*(1+ret_34)-1
gen wret_8=(1+ret_40)*(1+ret_36)*(1+ret_37)*(1+ret_38)*(1+ret_39)-1
gen wret_9=(1+ret_45)*(1+ret_41)*(1+ret_42)*(1+ret_43)*(1+ret_44)-1
gen wret_10=(1+ret_50)*(1+ret_46)*(1+ret_47)*(1+ret_48)*(1+ret_49)-1
gen wret_11=(1+ret_55)*(1+ret_51)*(1+ret_52)*(1+ret_53)*(1+ret_54)-1
gen wret_12=(1+ret_60)*(1+ret_56)*(1+ret_57)*(1+ret_58)*(1+ret_59)-1

gen futwret_1=(1+futret_1)*(1+futret_2)*(1+futret_3)*(1+futret_4)*(1+futret_5)-1
gen futwret_2=(1+futret_6)*(1+futret_7)*(1+futret_8)*(1+futret_9)*(1+futret_10)-1
gen futwret_3=(1+futret_11)*(1+futret_12)*(1+futret_13)*(1+futret_14)*(1+futret_15)-1
gen futwret_4=(1+futret_16)*(1+futret_17)*(1+futret_18)*(1+futret_19)*(1+futret_20)-1
gen futmret_1=(1+futwret_1)*(1+futwret_2)*(1+futwret_3)*(1+futwret_4)*(1+futret_21)-1

collapse lag_convexity wret* dow_1m fut*, by(year month day monthyear)

gen obs=_n

gen fit_expect_12=.
tsset obs

*12 lags
forval i=700/3575 {	
nl (dow_1m = {b0} + ///
	{b1}*(({b2}*wret_1)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^2*wret_2)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^3*wret_3)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^4*wret_4)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^5*wret_5)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^6*wret_6)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^7*wret_7)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^8*wret_8)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^9*wret_9)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^10*wret_10)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^11*wret_11)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^12*wret_12)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12)))  ///
		if obs<(`i'+1), initial(b0 0 b1 1 b2 0.5) nolog vce(cluster monthyear)

gen fit_expect =_b[/b0] + ///
	_b[/b1]*((_b[/b2]*wret_1)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12) + ///
		(_b[/b2]^2*wret_2)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12) + ///
		(_b[/b2]^3*wret_3)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12) + ///
		(_b[/b2]^4*wret_4)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]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b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12) + ///
		(_b[/b2]^12*wret_12)/(_b[/b2]+_b[/b2]^2+_b[/b2]^3+_b[/b2]^4+_b[/b2]^5+_b[/b2]^6+_b[/b2]^7+_b[/b2]^8+_b[/b2]^9+_b[/b2]^10+_b[/b2]^11+_b[/b2]^12))   if obs<(`i'+1)
	
replace fit_expect_12=fit_expect if obs==`i'
drop fit_expect
}

drop if missing(fit_expect_12)

replace fit_expect_12=fit_expect_12*100
replace futmret_1=futmret_1*100
replace dow_1m=dow_1m*100

gen res_expect_12=dow_1m-fit_expect_12
egen res_expect_12_std=std(res_expect_12)
egen fit_expect_12_std=std(fit_expect_12)
egen dow_1m_std=std(dow_1m)
egen convex_std=std(lag_convexity)
}

****TABLE 10****
*coefficients and t-stats
newey futmret_1 dow_1m_std, lag(8)
newey futmret_1 fit_expect_12_std, lag(8)
newey futmret_1 res_expect_12_std, lag(8)

*R-squared
reg futmret_1 dow_1m_std
reg futmret_1 fit_expect_12_std
reg futmret_1 res_expect_12_std

****TABLE 11****
*coefficients and t-stats
newey dow_1m convex_std, lag(8)
newey fit_expect_12 convex_std, lag(8)
newey res_expect_12 convex_std, lag(8)

*R-squared
reg dow_1m convex_std
reg fit_expect_12 convex_std
reg res_expect_12 convex_std
